fix: guard LLM response access before dereferencing choices/content#92
Open
qizwiz wants to merge 1 commit into
Open
fix: guard LLM response access before dereferencing choices/content#92qizwiz wants to merge 1 commit into
qizwiz wants to merge 1 commit into
Conversation
response.choices[0].message.content is Optional[str] in the OpenAI SDK — returns None (not raises) when finish_reason is tool_calls or the provider filters output. message.content[0].text is similarly unsafe on the Anthropic side when content is empty or filtered. Adds guards in three files: - autoagent/environment/mdconvert.py (OpenAI) - autoagent/environment/markdown_browser/mdconvert.py (OpenAI) - docs/translation_updater.py (Anthropic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Guard LLM response access in three files before dereferencing
.choices[0]or.content[0].Why
response.choices[0].message.contentis typedOptional[str]in the OpenAI SDK — it returnsNone(not raises) whenfinish_reasonis"tool_calls"or the provider applies content filtering. Similarly, the Anthropic SDK can return an emptycontentlist on filtered responses, makingmessage.content[0].textunsafe without a length check.autoagent/environment/mdconvert.pyandautoagent/environment/markdown_browser/mdconvert.py(OpenAI):docs/translation_updater.py(Anthropic):Test plan
translate_content()raisesValueErrorwhen given a mockmessage.content = []ValueErrorwhen given a mockresponse.choices = []🤖 Generated with Claude Code